home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / essent / FIXES / CSeries.exe / issue100 / CPROG10.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  703 b   |  21 lines

  1. /* CPROG10.CPP - Count the length of a string */
  2. #include <stdio.h>
  3.  
  4. int stringlen(char *string)    // Parameter is a pointer to the start of
  5.                 // the string whose length is to be counted.
  6. {
  7. char *t;            // Temporary pointer
  8.   t=string;                     // Point t at start of string.
  9.   while( *t++ )            // While the thing pointed to by t is true (non-zero), increment t
  10.      ;                // Do nothing
  11.   return (t-string-1);        // t points to 1 past '\0', so subtract 1
  12.                 // from difference between address in t and
  13.                 // address of start of string
  14. }
  15.  
  16. void main(void)
  17. (
  18. static char name[]="Count me!";    // Statics can be initialised during compilation
  19.    printf("%d\n", stringlen(name) );
  20. )
  21.